$(document).ready(function() {
	/* Horizontal scroll */	
	function startNav() {
	   $('#portfolioMainNavList').hoverscroll({
			fixedArrows: false,
			width:955,
			height:125,
			arrowsOpacity: 0.7
		});
	};
	/* Remove loading background */
	function removeImgBg() {
		$("img").each(function() {
			$(this).load(function() {
				$(this).css("background","none");
			}).error(function() {
				$(this).css("background","url('/templates/default/images/imgError.png') no-repeat 50% 50%");
			});	
		});
	};
	
	$(".corner").corner(); 
	$(".corner2").corner("top");
	$("input:not(:submit,:reset), textarea").corner("4px");
	$("#nav a, .goToAnchor").goToAnchor({margintop : 113});
	$('#bannerSlide').slideShow({interval: 10}, function() {
		removeImgBg();
	});

	
	startNav();
    
	removeImgBg();
	
	/* Rank */
    var starRank = -1;
    $("#portfolioRank a").live("mouseenter",function() {
        starRank = parseInt($(this).html());
        var counter = 0;
        $("#portfolioRank a").each(function() {
            if (counter < starRank)
                $(this).addClass("sfull");
            else
                $(this).removeClass("sfull");
            counter++;
        });
    }).live("mouseleave", function() {
        $("#portfolioRank a").each(function() {
            $(this).removeClass("sfull");
        });
        starRank = -1;
    }).live("click", function(e) {
        apprise("Em manutenção / Under maintenance.", {animate:true});
        e.preventDefault();
        return false
    });
	/* Portfolio inner nav */
    $("#portfolioMainNavList a").live("click", function(e) {
        $("#portfolioContentLoad").fadeOut(200);
        $("#portfolioLoading").fadeIn(200);
        $.get("content/" + $(".pactive").attr("href").substr(1) + "/" + $(this).attr("href").substr(1) + "/" + Math.random(),function(data) {
            $("#portfolioContentLoad").html(data).fadeIn(200);
            $("#portfolioLoading").fadeOut(200);
        });
        e.preventDefault();
        return false;
    });
	var po = 0.5;
	function pochange(tag, opacity) {
		tag.fadeTo(200,opacity).parent().siblings("span").fadeTo(200,opacity);
	};
	function teste(asd) {
	apprise(asd, {animation:true});
	}
	/* Portfolio nav */
	$("#portfolioNav a").live("click", function(e) {
        pochange($(".pactive"),po);
		$(".pactive").removeClass("pactive");
		$(this).addClass("pactive");
		pochange($(this),1);
		$("#portfolioMain").fadeOut(200);
        $("#portfolioLoading").fadeIn(200);
        $.get("portfolio/" + $(this).attr("href").substr(1) + "/" + Math.random(),function(data) {
            $("#portfolioMain").html(data).fadeIn(200);
			startNav();
			$(".corner2").corner("top");
            $("#portfolioLoading").fadeOut(200);
			removeImgBg();
        });
        e.preventDefault();
        return false;
    });
	$("#portfolioNav span:not(.icon_web), #portfolioNav li:not(::first-child) a").fadeTo(200, 0.5);
	//span hover
	$("#portfolioNav a").live("mouseover", function() {
		pochange($(this),1);
	}).live("mouseleave", function() {
		if(!$(this).hasClass("pactive"))
			pochange($(this),po);
	});
	/* Validate form */
    $("#form_contact").formValidate();
});